global root "C:\Users\hanwa\Desktop\replication"

***Data preparation for monthly panel
clear
use "$root\data\rawdata\IMC_HA_Monthly_Panel.dta"
gen imc = (startdate <= yearmonth)
gen no_treat = missing(startdate)
encode lacode, gen(lacoded)
order imc no_treat startdate, after(yearmonth)
gen kids = couplewkid / allclaim
gen private = privaterent / allclaim
gen umemploy = unemploy / allclaim
gen pension = (pension65 + pension70) / allclaim
gen vulnerable = passport / allclaim
gen lnclaim = ln(claimant)
gen deficit_rate = expenditure / (expenditure - deficit)
gen lnpop = ln(population)
gen grant_dependence = supportgrant / expenditure
gen lnwage = ln(wage)
encode lacode, gen(code)
egen region_ym = group(region yearmonth)
replace imcden_number = 1 if imcden_number == 0 | imc == 0
gen imc_dist = (imc == 1 & type == "district")
gen imc_nodist = (imc == 1 & type != "district")
gen imc_neighbor = (imc == 1 & neighbor == 1)
gen imc_noneighbor = (imc == 1 & neighbor == 0)
gen imc_small = (imc == 1 & pop <= 129431)
gen imc_nosmall = (imc == 1 & pop > 129431)
gen imc_demdev = (imc == 1 & complex1 >= 2451.185)
gen imc_nodemdev = (imc == 1 & complex1 < 2451.185)
gen imcsize = imcden_number - 1
gen imc_smallc = (imc == 1 & imcsize <= 2)
gen imc_nosmallc = (imc == 1 & imcsize > 2)
gen startyear = int(startdate / 100)
gen duration1 = year - startyear
gen imc1 = (inlist(duration1, 0, 1, 2))
gen imc2 = (duration1 > 2)
save "$root\data\IMC_HA_Monthly_Panel_clean.dta", replace
 
***Data preparation for quarterly panel
use "$root\data\rawdata\IMC_HA_Quarterly_Panel.dta", clear
gen imc = (startdate <= yearquarter)
replace imcden_number = 1 if imcden_number == 0 | imc == 0
gen lnclaim = ln(claimant)
gen lnupheld = ln(upheld + 1)
gen lncomplain = ln(complain + 1)
gen identir = identified / outstanding
replace identir = . if identir >= 1
gen recover = recovered / outstanding
replace recover = . if recover >= 1
gen writter = written / outstanding
replace writter = . if writter >= 1
gen deficit_rate = expenditure / (expenditure - deficit)
gen lnpop = ln(population)
gen grant_dependence = supportgrant / expenditure
gen lnwage = ln(wage)
egen region_yq = group(region yearquarter)
encode lacode, gen(code)
gen no_treat = missing(startdate)
gen imc_dist = (imc == 1 & type == "district")
gen imc_nodist = (imc == 1 & type != "district")
gen imc_small = (imc == 1 & pop <= 129431)
gen imc_nosmall = (imc == 1 & pop > 129431)
gen imc_demdev = (imc == 1 & complex1 >= 2451.185)
gen imc_nodemdev = (imc == 1 & complex1 < 2451.185)
gen imc_neighbor = (imc == 1 & neighbor == 1)
gen imc_noneighbor = (imc == 1 & neighbor == 0)
gen startyear = int(startdate / 100)
gen duration1 = year - startyear
gen imc1 = inlist(duration1, 0, 1, 2)
gen imc2 = (duration1 > 2)
save "$root\data\IMC_HA_Quarterly_Panel_clean.dta", replace

***Data preparation for yearly panel
use "$root\data\rawdata\IMC_HA_Yearly_Panel.dta", clear
gen imc = (startyear <= year)
gen no_treat = missing(startyear)
encode lacode, gen(code)
gen lnclaim = ln(claimant)
gen lnexpend = ln(netcurrentexpenditure)
gen deficit_rate = expenditure / (expenditure - deficit)
gen lnpop = ln(population)
gen grant_dependence = supportgrant / expenditure
gen lnwage = ln(wage)
egen region_y = group(region year)
gen imc_dist = (imc == 1 & type == "district")
gen imc_nodist = (imc == 1 & type != "district")
gen imc_small = (imc == 1 & pop <= 135013)
gen imc_nosmall = (imc == 1 & pop > 135013)
gen imc_smallcl = (imc == 1 & claim <= 7717.944)
gen imc_nosmallcl = (imc == 1 & claim > 7717.944)
gen imcsize = imcden_number - 1
gen imc_smallc = (imc == 1 & imcsize <= 2)
gen imc_nosmallc = (imc == 1 & imcsize > 2)
gen imc_neighbor = (imc == 1 & neighbor == 1)
gen imc_noneighbor = (imc == 1 & neighbor == 0)
gen duration1 = year - startyear
gen imc1 = inlist(duration1, 0, 1, 2)
gen imc2 = (duration1 > 2)
save "$root\data\IMC_HA_Yearly_Panel_clean.dta", replace
